var $, element, layer, laydate, form;
// 加载元素控件
layui.use(['jquery', 'element', 'layer', 'laydate', 'form', 'table'], function () {
    $ = layui.jquery, element = layui.element, layer = layui.layer, laydate = layui.laydate, form = layui.form, table = layui.table;
    $('.fa-caret-right').click(function () {
        var index = parent.layer.getFrameIndex(window.name); // 先得到当前iframe层的索引
        parent.layer.close(index); // 再执行关闭
    });
    var roomid = QueryUtils.GetQueryString("roomid");
    var contractID = "";
    var HistoryContractID = "";
    //console.log(roomid);
    //roomid='14a65c9e6327434cad4b10373e7c9345';//2017年9月27日 21:39:55测试数据
    if (null != roomid) {
        //获取房间基本信息
        $.ajax({
            url: "/room/info/",
            data: {ROOM_ID: roomid},
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                if (res.errcode === "0") {
                    //房间面积
                    $(".roomarea").html(res.data.ROOM_AREA);
                    //获取房间单元
                    $(".unit").html(TypeUtils.NumberToChinese(res.unit));
                    //获取房间号
                    $(".roomnum").html(res.roomnum);
                } else if (res.errcode === "1") {
                    layer.msg(res.errmsg, function () {
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });

        //获取当前房间当前合同信息
        $.ajax({
            url: "/contract/list",
            data: {ROOM_ID: roomid, cod: 1},
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                if (res.errcode === "0") {
                    var k = 1;
                    for (var i = 0; i < res.ConSum; i++) {
                        $(".conItem").append('<input type="radio" name="ceshi" lay-filter="htitem"  id="htitem' + i + '" value="' + i + '" title="合同' + k + '">');
                        k++;
                        $('#htitem0').attr('checked', 'checked');

                    }
                    form.render();
                    //监听提交
                    form.on('radio(htitem)', function (data) {
                        if (0 == data.value) {
                            $('#htitem1').attr('checked', false);
                        }
                        if (1 == data.value) {
                            $('#htitem0').attr('checked', false);
                        }
                        form.render();
                        var cod = data.value;
                        $.ajax({
                            url: "/contract/list",
                            data: {ROOM_ID: roomid, cod: cod},
                            dataType: "json",
                            type: "post",
                            async: false,
                            success: function (res) {
                                if (res.errcode === "0") {
                                    //获取选中合同的内容
                                    //承租人信息
                                    $(".CON_DATE").html(res.data.con_date);//签订日期
                                    $(".CON_END_DATE").html((res.data.con_end_date));//结束日期
                                    $(".COMPANY").html(res.data.COMPANY);//公司
                                    $(".TRADE").html(res.data.TRADE);//所属行业
                                    $(".LEG_REN").html(res.data.LEG_REN);//法人
                                    $(".LEG_TEL").html(res.data.LEG_TEL);//法人电话
                                    $(".SIGN_REN").html(res.data.SIGNER);//签订人
                                    $(".SIGN_TEL").html(res.data.SIGNER_TEL);//签订人电话
                                    $(".ADDRESS").html(res.data.ADDRESS);//通新地址
                                    contractID = res.data.id;//合同id
                                    //合同信息
                                    $(".contract_num").html(res.data.contract_num);//合同编号
                                    $(".CON_HR_DATE").html((res.data.con_hr_date));
                                    $(".zfht").hide();
                                    if (undefined == res.data.contract_num) {
                                        $(".contractItem").empty();
                                        $(".contractItem").html("暂无合同");
                                        $(".czrxx").html("<br>");
                                        $(".zlxx").html("");
                                        return;
                                    }
                                    if ("9" == res.data.CHECK_STATE) {
                                        //作废
                                        $(".zfht").show();
                                        $(".contractItem").html("合同已作废");
                                        $(".czrxx").html("<br>");
                                        $(".zlxx").html("");
                                        $(".property-info").html();
                                        return;
                                    }
                                    if ("0" == res.data.CHECK_STATE) {
                                        //新建待审核
                                        if ("93fc91b97d144550aed7ea1c01dd3w03" == res.data.state) {
                                            $(".contractItem").html("合同暂存中");
                                        } else {
                                            $(".contractItem").html("合同新建审核中");
                                        }
                                        $(".czrxx").html("<br>");
                                        $(".zlxx").html("");
                                        return;
                                    }
                                    if (res.data.PAY_TYPE == 0) {
                                        $(".ant_pay_day").html("提前" + res.data.ant_pay_day + "天");
                                    } else if (res.data.PAY_TYPE == 1) {
                                        $(".ant_pay_day").html("固定每月" + res.data.ant_pay_day + "号");
                                    }
                                    //$(".ant_pay_day").html(res.data.ant_pay_day);// 付款天数
                                    $(".BOND").html(res.data.BOND);//保证金
                                    //$(".CON_DATE").html((res.data.con_date).substring(0,11));//合同签订日期  substring console 报错
                                    $(".rent").html(res.data.rent);//租金单价
                                    $(".con_hr_date").html(res.data.con_hr_date);//合同计租开始时间
                                    $(".pay_bet").html(res.data.BOND);//支付方式 押
                                    //$(".pay_pay").html('付'+res.data.rent);//支付方式 付
                                    $(".con_end_date").html(res.data.con_end_date);//合同结束日期
                                    $(".INCR_RATE").html(res.data.INCR_RATE);//递增率
                                    //收租明细
                                    //水电表
                                    $(".CHARGE_DATE").html(res.data.CHARGE_DATE);//抄表后 x天 付费
                                    $(".CHARGE_PRICE").html(res.data.CHARGE_PRICE);//费用单价
                                    $(".INIT_READ").html(res.data.INIT_READ);//初始读数
                                    $(".INIT_READ_TIME").html(res.data.INIT_READ_TIME);//读数时间
                                    $(".PAY_DATE").html(res.data.PAY_DATE);//付款周期
                                    var property = res.property;//物业基本信息
                                    var initRead = res.initRead;
                                    var discount = res.discount;//年递增率
                                    if (res.data.INCREAS_TYPE == 0) {
                                        $(".increas_type").html("原始租金递增");
                                    } else if (res.data.INCREAS_TYPE == 1) {
                                        $(".increas_type").html("上年租金递增");
                                    }
                                    var contractLateFee = res.data.LATE_FEE;
                                    if (!contractLateFee || contractLateFee == " - ") {
                                        contractLateFee = 0;
                                    }
                                    $(".late_fee").html("滞纳金：年租金的 " + contractLateFee + "%");

                                    $(".discounts").empty();
                                    if (!!discount) {
                                        for (var i = 0; i < discount.length; i++) {
                                            var LATE_FEE = discount[i].LATE_FEE;
                                            if (undefined == LATE_FEE) {
                                                LATE_FEE = 0;
                                            }
                                            var str = '<div class="layui-input-inline">\n' +
                                                '          <span>第' + TypeUtils.NumberToChinese(discount[i].FIRST_YEAR) + '年：递增率：' + discount[i].INCREAS_RATE + '%；折扣：' + discount[i].DISCOUNT + '折；折后价格：' + discount[i].DISCOUNT_RENT + '；滞纳金：' + LATE_FEE + '元/天。</span>\n' +
                                                '      </div>';
                                            $(".discounts").append(str);
                                        }
                                    }
                                    //物业信息
                                    $(".property-info").empty();
                                    if (!!property) {
                                        for (var i = 0; i < property.length; i++) {
                                            // $(".property-fpzb").html(property[i].PROPERTY_FPZB);
                                            var sffs = '';
                                            var initReadStr = "";
                                            if (property[i].CHARGE_TYPE == 0) {
                                                sffs = '固定价格';
                                            } else if (property[i].CHARGE_TYPE == 1) {
                                                sffs = '抄表收费';
                                                if (property[i].PROPERTY_TYPE_ID == 'a14e6f2e190e4492badac72e9b42152e' || property[i].PROPERTY_TYPE_ID == 'ddcf9b35bbe04cd88834e21c1fd74f32') {
                                                    if (!!initRead) {
                                                        initReadStr += '<div class="layui-form-item">\n' +
                                                            '                                    <div class="layui-inline">\n' +
                                                            '                                        初始读数：\n' +
                                                            '                                    </div>\n' +
                                                            '                                    <div class="layui-inline">\n';
                                                        for (var j = 0; j < initRead.length; j++) {
                                                            if (property[i].PROPERTY_TYPE_ID == initRead[j].PROPERTY_TYPE_ID) {
                                                                initReadStr += '<div class="layui-input-inline" style="width: auto;">\n' +
                                                                    '               <span>' + initRead[j].CODE + ' 读数：' + initRead[j].INIT_READ + ' 日期：' + initRead[j].INIT_READ_TIME + '</span>\n' +
                                                                    '           </div><br>';
                                                            }
                                                        }
                                                        initReadStr += '                    </div>\n' +
                                                            '                                </div>';
                                                    }
                                                }
                                            } else if (property[i].CHARGE_TYPE == 2) {
                                                sffs = '按面积收费';
                                            } else if (property[i].CHARGE_TYPE == 3) {
                                                sffs = '即时收费';
                                                if (property[i].PROPERTY_TYPE_ID == 'a14e6f2e190e4492badac72e9b42152e' || property[i].PROPERTY_TYPE_ID == 'ddcf9b35bbe04cd88834e21c1fd74f32') {
                                                    if (!!initRead) {
                                                        initReadStr += '<div class="layui-form-item">\n' +
                                                            '                                    <div class="layui-inline">\n' +
                                                            '                                        初始读数：\n' +
                                                            '                                    </div>\n' +
                                                            '                                    <div class="layui-inline">\n';
                                                        for (var j = 0; j < initRead.length; j++) {
                                                            if (property[i].PROPERTY_TYPE_ID == initRead[j].PROPERTY_TYPE_ID) {
                                                                initReadStr += '<div class="layui-input-inline" style="width: auto;">\n' +
                                                                    '               <span>' + initRead[j].CODE + ' 读数：' + initRead[j].INIT_READ + ' 日期：' + initRead[j].INIT_READ_TIME + '</span>\n' +
                                                                    '           </div><br>';
                                                            }
                                                        }
                                                        initReadStr += '                    </div>\n' +
                                                            '                                </div>';
                                                    }
                                                }
                                            }
                                            var dw = '';
                                            if (property[i].PROPERTY_TYPE_ID == 'a14e6f2e190e4492badac72e9b42152e') {
                                                if (property[i].CHARGE_TYPE == 1) {
                                                    dw = '元/吨';
                                                } else {
                                                    dw = '元/月';
                                                }
                                            } else if (property[i].PROPERTY_TYPE_ID == 'ddcf9b35bbe04cd88834e21c1fd74f32') {
                                                if (property[i].CHARGE_TYPE == 1) {
                                                    dw = '元/度';
                                                } else {
                                                    dw = '元/月';
                                                }
                                            } else if (property[i].PROPERTY_TYPE_ID == '669791dac4894160bc8d79b484519e96' || property[i].PROPERTY_TYPE_ID == '7b05982a081e41deb9b46a1f6f5ed5fa') {
                                                if (property[i].DEFAULT_ID == "-1") {
                                                    dw = '元/年';
                                                } else {
                                                    dw = '元/㎡·天';
                                                }
                                            } else {
                                                if (property[i].CHARGE_TYPE == 0) {
                                                    dw = '元/月';
                                                } else if (property[i].CHARGE_TYPE == 2) {
                                                    dw = '元/㎡·天';
                                                }
                                            }

                                            var jg = property[i].CHARGE_PRICE;
                                            if (!jg) {
                                                jg = 0;
                                            }
                                            if (property[i].IS_DEFAULT == 0) {
                                                jg = jg + dw;
                                            } else if (property[i].IS_DEFAULT == 1) {
                                                jg = property[i].DEFAULT_PRICE + dw;
                                            }
                                            var sfrq = '';
                                            if (property[i].CHARGE_DATE_TYPE == 0) {
                                                sfrq = '提前' + property[i].CHARGE_DATE + '天';
                                            } else if (property[i].CHARGE_DATE_TYPE == 1) {
                                                sfrq = '固定' + property[i].CHARGE_DATE + '号';
                                            } else if (property[i].CHARGE_DATE_TYPE == 2) {
                                                sfrq = '抄表后' + property[i].CHARGE_DATE + '天';
                                            }
                                            var sffsStr = '';
                                            var fkzqStr = property[i].PAY_DATE;
                                            if (property[i].PROPERTY_TYPE_ID == '669791dac4894160bc8d79b484519e96' || property[i].PROPERTY_TYPE_ID == '7b05982a081e41deb9b46a1f6f5ed5fa') {
                                                fkzqStr = property[i].DATE_START_MONTH + "月" + property[i].DATE_START_DAY + "日 至 " + property[i].DATE_END_MONTH + "月" + property[i].DATE_END_DAY + "日";
                                            } else {
                                                fkzqStr += "月";
                                                sffsStr += '     <div class="layui-form-item">\n' +
                                                    '                   <div class="layui-inline">\n' +
                                                    '                       收费方式：' + sffs + '\n' +
                                                    '                   </div>\n' +
                                                    '               </div>\n';
                                            }
                                            var info = property[i].INFO;
                                            if (!info) {
                                                info = "";
                                            }
                                            var str = '<fieldset class="layui-elem-field">\n' +
                                                '           <legend>' + property[i].CODE + '</legend>\n' +
                                                '           <div class="layui-field-box">\n' +
                                                '               <div class="layui-form-item">\n' +
                                                '                   <div class="layui-inline">\n' +
                                                '                       发票占比：' + property[i].PROPERTY_FPZB + '%\n' +
                                                '                   </div>\n' +
                                                '               </div>\n' +
                                                '               <div class="layui-form-item">\n' +
                                                '                   <div class="layui-inline">\n' +
                                                '                       付款周期：' + fkzqStr + '\n' +
                                                '                   </div>\n' +
                                                '               </div>\n';
                                            str += sffsStr;
                                            str += initReadStr;
                                            if (property[i].CHARGE_TYPE != "3") {
                                                str += '               <div class="layui-form-item">\n' +
                                                    '                   <div class="layui-inline">\n' +
                                                    '                       价格：' + jg + '\n' +
                                                    '                   </div>\n' +
                                                    '               </div>\n';
                                            }
                                            var pStr = "收费";
                                            if (property[i].CHARGE_TYPE == "3") {
                                                pStr = "提醒";
                                            }
                                            str += '               <div class="layui-form-item">\n' +
                                                '                   <div class="layui-inline">\n' +
                                                '                       ' + pStr + '日期：' + sfrq + '\n' +
                                                '                   </div>\n' +
                                                '               </div>\n' +
                                                '               <div class="layui-form-item">\n' +
                                                '                   <div class="layui-inline">\n' +
                                                '                       备注：' + info + '\n' +
                                                '                   </div>\n' +
                                                '               </div>\n' +
                                                '           </div>\n' +
                                                '       </fieldset>';
                                            $(".property-info").append(str);
                                        }
                                    }


                                } else if (res.errcode === "1") {
                                    layer.msg(res.errmsg, function () {
                                    });
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                console.error(XMLHttpRequest.status);
                                console.error(XMLHttpRequest.readyState);
                                console.error(textStatus);
                            }
                        });
                    });
                    //切换合同 获取选中合同的内容
                    $('.select').click(function (e) {
                        var cod = $(this).find("#selectCon").val();
                    });
                    //承租人信息
                    $(".CON_DATE").html(res.data.con_date);//签订日期
                    $(".CON_END_DATE").html((res.data.con_end_date));//结束日期
                    $(".COMPANY").html(res.data.COMPANY);//公司
                    $(".TRADE").html(res.data.TRADE);//所属行业
                    $(".LEG_REN").html(res.data.LEG_REN);//法人
                    $(".LEG_TEL").html(res.data.LEG_TEL);//法人电话
                    $(".SIGN_REN").html(res.data.SIGNER);//签订人
                    $(".SIGN_TEL").html(res.data.SIGNER_TEL);//签订人电话
                    $(".ADDRESS").html(res.data.ADDRESS);//通新地址
                    contractID = res.data.id;//合同id
                    //合同信息
                    $(".contract_num").html(res.data.contract_num);//合同编号
                    $(".CON_HR_DATE").html((res.data.con_hr_date));
                    $(".zfht").hide();
                    if (undefined == res.data.contract_num) {
                        $(".contractItem").empty();
                        $(".contractItem").html("暂无合同");
                        $(".czrxx").html("<br>");
                        $(".zlxx").html("");
                        return;
                    }
                    if ("9" == res.data.CHECK_STATE) {
                        //作废
                        $(".zfht").show();
                        $(".contractItem").html("合同已作废");
                        $(".czrxx").html("<br>");
                        $(".zlxx").html("");
                        $(".property-info").html();
                        return;
                    }
                    if ("0" == res.data.CHECK_STATE) {
                        //新建待审核
                        if ("93fc91b97d144550aed7ea1c01dd3w03" == res.data.state) {
                            $(".contractItem").html("合同暂存中");
                        } else {
                            $(".contractItem").html("合同新建审核中");
                        }
                        $(".czrxx").html("<br>");
                        $(".zlxx").html("");
                        return;
                    }
                    if (res.data.PAY_TYPE == 0) {
                        $(".ant_pay_day").html("提前" + res.data.ant_pay_day + "天");
                    } else if (res.data.PAY_TYPE == 1) {
                        $(".ant_pay_day").html("固定每月" + res.data.ant_pay_day + "号");
                    }
                    //$(".ant_pay_day").html(res.data.ant_pay_day);// 付款天数
                    $(".BOND").html(res.data.BOND);//保证金
                    //$(".CON_DATE").html((res.data.con_date).substring(0,11));//合同签订日期  substring console 报错
                    $(".rent").html(res.data.rent);//租金单价
                    $(".con_hr_date").html(res.data.con_hr_date);//合同计租开始时间
                    $(".pay_bet").html(res.data.BOND);//支付方式 押
                    //$(".pay_pay").html('付'+res.data.rent);//支付方式 付
                    $(".con_end_date").html(res.data.con_end_date);//合同结束日期
                    $(".INCR_RATE").html(res.data.INCR_RATE);//递增率
                    //收租明细
                    //水电表
                    $(".CHARGE_DATE").html(res.data.CHARGE_DATE);//抄表后 x天 付费
                    $(".CHARGE_PRICE").html(res.data.CHARGE_PRICE);//费用单价
                    $(".INIT_READ").html(res.data.INIT_READ);//初始读数
                    $(".INIT_READ_TIME").html(res.data.INIT_READ_TIME);//读数时间
                    $(".PAY_DATE").html(res.data.PAY_DATE);//付款周期
                    var property = res.property;//物业基本信息
                    var initRead = res.initRead;
                    var discount = res.discount;//年递增率
                    if (res.data.INCREAS_TYPE == 0) {
                        $(".increas_type").html("原始租金递增");
                    } else if (res.data.INCREAS_TYPE == 1) {
                        $(".increas_type").html("上年租金递增");
                    }
                    var contractLateFee = res.data.LATE_FEE;
                    if (!contractLateFee || contractLateFee == " - ") {
                        contractLateFee = 0;
                    }
                    $(".late_fee").html("滞纳金：年租金的 " + contractLateFee + "%");

                    $(".discounts").empty();
                    if (!!discount) {
                        for (var i = 0; i < discount.length; i++) {
                            var LATE_FEE = discount[i].LATE_FEE;
                            if (undefined == LATE_FEE) {
                                LATE_FEE = 0;
                            }
                            var str = '<div class="layui-input-inline">\n' +
                                '          <span>第' + TypeUtils.NumberToChinese(discount[i].FIRST_YEAR) + '年：递增率：' + discount[i].INCREAS_RATE + '%；折扣：' + discount[i].DISCOUNT + '折；折后价格：' + discount[i].DISCOUNT_RENT + '；滞纳金：' + LATE_FEE + '元/天。</span>\n' +
                                '      </div>';
                            $(".discounts").append(str);
                        }
                    }
                    //物业信息
                    $(".property-info").empty();
                    if (!!property) {
                        for (var i = 0; i < property.length; i++) {
                            // $(".property-fpzb").html(property[i].PROPERTY_FPZB);
                            var sffs = '';
                            var initReadStr = "";
                            if (property[i].CHARGE_TYPE == 0) {
                                sffs = '固定价格';
                            } else if (property[i].CHARGE_TYPE == 1) {
                                sffs = '抄表收费';
                                if (property[i].PROPERTY_TYPE_ID == 'a14e6f2e190e4492badac72e9b42152e' || property[i].PROPERTY_TYPE_ID == 'ddcf9b35bbe04cd88834e21c1fd74f32') {
                                    if (!!initRead) {
                                        initReadStr += '<div class="layui-form-item">\n' +
                                            '                                    <div class="layui-inline">\n' +
                                            '                                        初始读数：\n' +
                                            '                                    </div>\n' +
                                            '                                    <div class="layui-inline">\n';
                                        for (var j = 0; j < initRead.length; j++) {
                                            if (property[i].PROPERTY_TYPE_ID == initRead[j].PROPERTY_TYPE_ID) {
                                                initReadStr += '<div class="layui-input-inline" style="width: auto;">\n' +
                                                    '               <span>' + initRead[j].CODE + ' 读数：' + initRead[j].INIT_READ + ' 日期：' + initRead[j].INIT_READ_TIME + '</span>\n' +
                                                    '           </div><br>';
                                            }
                                        }
                                        initReadStr += '                    </div>\n' +
                                            '                                </div>';
                                    }
                                }
                            } else if (property[i].CHARGE_TYPE == 2) {
                                sffs = '按面积收费';
                            } else if (property[i].CHARGE_TYPE == 3) {
                                sffs = '即时收费';
                                if (property[i].PROPERTY_TYPE_ID == 'a14e6f2e190e4492badac72e9b42152e' || property[i].PROPERTY_TYPE_ID == 'ddcf9b35bbe04cd88834e21c1fd74f32') {
                                    if (!!initRead) {
                                        initReadStr += '<div class="layui-form-item">\n' +
                                            '                                    <div class="layui-inline">\n' +
                                            '                                        初始读数：\n' +
                                            '                                    </div>\n' +
                                            '                                    <div class="layui-inline">\n';
                                        for (var j = 0; j < initRead.length; j++) {
                                            if (property[i].PROPERTY_TYPE_ID == initRead[j].PROPERTY_TYPE_ID) {
                                                initReadStr += '<div class="layui-input-inline" style="width: auto;">\n' +
                                                    '               <span>' + initRead[j].CODE + ' 读数：' + initRead[j].INIT_READ + ' 日期：' + initRead[j].INIT_READ_TIME + '</span>\n' +
                                                    '           </div><br>';
                                            }
                                        }
                                        initReadStr += '                    </div>\n' +
                                            '                                </div>';
                                    }
                                }
                            }
                            var dw = '';
                            if (property[i].PROPERTY_TYPE_ID == 'a14e6f2e190e4492badac72e9b42152e') {
                                if (property[i].CHARGE_TYPE == 1) {
                                    dw = '元/吨';
                                } else {
                                    dw = '元/月';
                                }
                            } else if (property[i].PROPERTY_TYPE_ID == 'ddcf9b35bbe04cd88834e21c1fd74f32') {
                                if (property[i].CHARGE_TYPE == 1) {
                                    dw = '元/度';
                                } else {
                                    dw = '元/月';
                                }
                            } else if (property[i].PROPERTY_TYPE_ID == '669791dac4894160bc8d79b484519e96' || property[i].PROPERTY_TYPE_ID == '7b05982a081e41deb9b46a1f6f5ed5fa') {
                                if (property[i].DEFAULT_ID == "-1") {
                                    dw = '元/年';
                                } else {
                                    dw = '元/㎡·天';
                                }
                            } else {
                                if (property[i].CHARGE_TYPE == 0) {
                                    dw = '元/月';
                                } else if (property[i].CHARGE_TYPE == 2) {
                                    dw = '元/㎡·天';
                                }
                            }

                            var jg = property[i].CHARGE_PRICE;
                            if (!jg) {
                                jg = 0;
                            }
                            if (property[i].IS_DEFAULT == 0) {
                                jg = jg + dw;
                            } else if (property[i].IS_DEFAULT == 1) {
                                jg = property[i].DEFAULT_PRICE + dw;
                            }
                            var sfrq = '';
                            if (property[i].CHARGE_DATE_TYPE == 0) {
                                sfrq = '提前' + property[i].CHARGE_DATE + '天';
                            } else if (property[i].CHARGE_DATE_TYPE == 1) {
                                sfrq = '固定' + property[i].CHARGE_DATE + '号';
                            } else if (property[i].CHARGE_DATE_TYPE == 2) {
                                sfrq = '抄表后' + property[i].CHARGE_DATE + '天';
                            }
                            var sffsStr = '';
                            var fkzqStr = property[i].PAY_DATE;
                            if (property[i].PROPERTY_TYPE_ID == '669791dac4894160bc8d79b484519e96' || property[i].PROPERTY_TYPE_ID == '7b05982a081e41deb9b46a1f6f5ed5fa') {
                                // fkzqStr = property[i].DATE_START_MONTH + "月" + property[i].DATE_START_DAY + "日 至 " + property[i].DATE_END_MONTH + "月" + property[i].DATE_END_DAY + "日";
                                fkzqStr += "月";
                            } else {
                                fkzqStr += "月";
                                sffsStr += '     <div class="layui-form-item">\n' +
                                    '                   <div class="layui-inline">\n' +
                                    '                       收费方式：' + sffs + '\n' +
                                    '                   </div>\n' +
                                    '               </div>\n';
                            }
                            var info = property[i].INFO;
                            if (!info) {
                                info = "";
                            }
                            console.log(property)
                            var str = '<fieldset class="layui-elem-field">\n' +
                                '           <legend>' + property[i].CODE + '</legend>\n' +
                                '           <div class="layui-field-box">\n' +
                                '               <div class="layui-form-item">\n' +
                                '                   <div class="layui-inline">\n' +
                                '                       发票占比：' + property[i].PROPERTY_FPZB + '%\n' +
                                '                   </div>\n' +
                                '               </div>\n';

                            var lateFeeStr = ' <div class="layui-form-item">\n' +
                                '                   <div class="layui-inline">\n' +
                                '                       滞纳金比率：当前账单的' + property[i].LATE_FEE + '%\n' +
                                '                   </div>\n' +
                                '               </div>\n' +
                                '               <div class="layui-form-item">\n' +
                                '                   <div class="layui-inline">\n' +
                                '                       滞纳金执行日：付款日后' + property[i].LATE_FEE_DAYS + '天\n' +
                                '                   </div>\n' +
                                '               </div>\n';
                            if (property[i].PROPERTY_TYPE_ID == 'a14e6f2e190e4492badac72e9b42152e' || property[i].PROPERTY_TYPE_ID == 'ddcf9b35bbe04cd88834e21c1fd74f32') {
                                str += lateFeeStr;
                            } else {
                                str += '  <div class="layui-form-item">\n' +
                                    '         <div class="layui-inline">\n' +
                                    '             计费周期：固定天数：' + property[i].PAY_DAYS + '天\n' +
                                    '         </div>\n' +
                                    '     </div>\n';
                            }


                            str += '               <div class="layui-form-item">\n' +
                                '                   <div class="layui-inline">\n' +
                                '                       付款周期：' + fkzqStr + '\n' +
                                '                   </div>\n' +
                                '               </div>\n';
                            str += sffsStr;
                            str += initReadStr;
                            if (property[i].CHARGE_TYPE != "3") {
                                str += '               <div class="layui-form-item">\n' +
                                    '                   <div class="layui-inline">\n' +
                                    '                       价格：' + jg + '\n' +
                                    '                   </div>\n' +
                                    '               </div>\n';
                            }
                            var pStr = "收费";
                            if (property[i].CHARGE_TYPE == "3") {
                                pStr = "提醒";
                            }
                            str += '               <div class="layui-form-item">\n' +
                                '                   <div class="layui-inline">\n' +
                                '                       ' + pStr + '日期：' + sfrq + '\n' +
                                '                   </div>\n' +
                                '               </div>\n' +
                                '               <div class="layui-form-item">\n' +
                                '                   <div class="layui-inline">\n' +
                                '                       付款提醒：付款日前' + property[i].PAY_TX_DAYS + '天\n' +
                                '                   </div>\n' +
                                '               </div>\n' +
                                '               <div class="layui-form-item">\n' +
                                '                   <div class="layui-inline">\n' +
                                '                       备注：' + info + '\n' +
                                '                   </div>\n' +
                                '               </div>\n' +
                                '           </div>\n' +
                                '       </fieldset>';
                            $(".property-info").append(str);
                        }
                    }


                } else if (res.errcode === "1") {
                    layer.msg(res.errmsg, function () {
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });
        //加载历史合同

        $.ajax({
            url: "/contract/HistoryContract",
            data: {ROOM_ID: roomid},
            dataType: "json",
            type: "post",
            async: false,
            success: function (res) {
                if (res.errcode === "0") {
                    //获取选中合同的内容
                    for (var i = 0; i < res.data.length; i++) {
                        HistoryContractID = res.data[i].id;//合同id
                        $(".zfht").show();
                        $(".zfht").append(' 合同编号:' + res.data[i].contract_num + '（合同周期:<span class="History_CON_HR_DATE">' + res.data[i].con_hr_date + '</span>至 <span class="History_CON_END_DATE">' + res.data[i].con_end_date + '</span>）\n' +
                            '                                                <a href="javascript:;" id="" class="layui-btn layui-btn-mini History_view">查看<input type="hidden" class="hiddenCon" value="' + HistoryContractID + '"/></a><hr>');
                        $(".contract_num").html(res.data[i].contract_num);//合同编号
                        // $(".History_CON_HR_DATE").html(res.data[i].con_hr_date);//合同计租开始时间
                        // $(".History_CON_END_DATE").html(res.data[i].con_end_date);//合同结束日期
                    }
                    //合同信息


                } else if (res.errcode === "1") {
                    layer.msg(res.errmsg, function () {
                    });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.error(XMLHttpRequest.status);
                console.error(XMLHttpRequest.readyState);
                console.error(textStatus);
            }
        });


    }
    //新建合同页面
    $(".jia").click(function () {
        if ($(".AUTH-HTQX_LR").length >= 1) {
            parent.layer.open({
                zIndex: 1000,
                type: 2,    //弹出类型
                title: '新建合同申请',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['1000px', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/contract_add.html?ROOM_ID=' + roomid + ''  //iframe的url
            });
        }

        $(this).blur(); //移除焦点，防止点击回车按钮造成多次打开
    });
    //收租提交
    $("input[name='tijiao']").click(function (e) {
        layer.msg('收租成功！');
    });
    //添加账单
    $(".tjzd").click(function (e) {
        debugger

        if ($(".AUTH-CWQX_TJZD").length >= 1) {
            parent.layer.open({
                zIndex: 1000,
                type: 2,    //弹出类型
                title: '添加账单',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['1000px', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/bill_add.html?ROOM_ID=' + roomid + ''  //iframe的url
            });
        }
        $(this).blur(); //移除焦点，防止点击回车按钮造成多次打开
    });
    //加载账单
    layui.use('table', function () {
        var table = layui.table;
        //获取当前月
        var date_ = new Date();
        var year = date_.getFullYear();
        var month = date_.getMonth() + 1;
        var paystar = year + '-' + month + '-01'
        var day = new Date(year, month, 0);
        var payend = year + '-' + month + '-' + day.getDate();
        var data = {};
        data.paystar = paystar;
        data.payend = payend;
        data.roomid = roomid;
        //待处理账单
        table.render({
            elem: '#daichuli'
            , url: '/billController/json'
            , where: data
            , cols: [[
                {checkbox: false, width: 5}
                , {field: 'START_DATE', event: 'setSign', title: '账单周期', width: 170}
                , {field: 'BILL_NAME', event: 'setSign', title: '账单类型', width: 78}
                , {field: 'STATE', event: 'setSign', title: '账单状态', width: 78}
                , {field: 'TOTAL_PRICE', event: 'setSign', title: '账单金额', width: 100}
                , {field: 'PAY_DATE', event: 'setSign', title: '应收租日', width: 92}
                , {field: 'INFO', event: 'setSign', title: '备注', width: 55}
                , {field: '', event: 'setSign', title: '操作', align: 'center', toolbar: '#dclbar', width: 120}

            ]]
            , id: ''
            , page: true
            , height: 'auto'
            , limit: '10'
            , size: 'sm' //小尺寸的表格
        });
        //未来账单
        table.render({
            elem: '#weilai'
            , url: '/billController/listPayNext'
            , page: true
            , where: data
            , limit: 10
            , height: 'auto'
            , cols: [[
                {checkbox: false, width: 5}
                , {field: 'START_DATE', event: 'setSign', title: '账单周期', width: 170}
                , {field: 'BILL_NAME', event: 'setSign', title: '账单类型', width: 78}
                , {field: 'STATE', event: 'setSign', title: '账单状态', width: 78}
                , {field: 'TOTAL_PRICE', event: 'setSign', title: '账单金额', width: 100}
                , {field: 'PAY_DATE', event: 'setSign', title: '应收租日', width: 92}
                , {field: 'INFO', event: 'setSign', title: '备注', width: 55}
                , {field: '', event: 'setSign', title: '操作', align: 'center', toolbar: '#wlbar', width: 120}

            ]]
            , id: ''
            , height: 'auto'
            , size: 'sm' //小尺寸的表格
        });
        //已处理账单
        table.render({
            elem: '#yichuli'
            , url: '/billController/listPayOk'
            , where: data
            , cols: [[
                {checkbox: false, width: 5}
                , {field: 'START_DATE', event: 'setSign', title: '账单周期', width: 170}
                , {field: 'BILL_NAME', event: 'setSign', title: '账单类型', width: 78}
                , {field: 'STATE', event: 'setSign', title: '账单状态', width: 78}
                , {field: 'TOTAL_PRICE', event: 'setSign', title: '账单金额', width: 78}
                , {field: 'PAY_DATE', event: 'setSign', title: '应收租日', width: 92}
                , {field: 'INFO', event: 'setSign', title: '备注', width: 55}
                , {field: '', event: 'setSign', title: '操作', align: 'center', toolbar: '#yclbar', width: 120}

            ]]
            , id: ''
            , page: true
            , height: 'auto'
            , limit: '10'
            , size: 'sm' //小尺寸的表格
        });
        //加载自用账单
        table.render({
            elem: '#ziyong'
            , url: '/billController/listPayziyongRoom'
            , where: data
            , cols: [[
                /* {checkbox: true, LAY_CHECKED: true} //默认全选*/
                /*,{field: 'BUILDING_NAME', event: 'setSign', title: '楼宇名称', width: 160}
                , {field: 'ROOM_NUM', event: 'setSign', title: '房号', width: 120}
                , {field: 'COMPANY_NAME', event: 'setSign', title: '承租方', width: 120}
                , {field: 'BYNAME', event: 'setSign', title: '别名', width: 120}*/
                {field: 'START_DATE', event: 'setSign', title: '账单周期', width: 170, sort: 'true'}
                , {field: 'BILL_NAME', event: 'setSign', title: '账单类型', width: 120, sort: 'true'}
                , {field: 'TOTAL_PRICE', event: 'setSign', title: '账单金额', width: 120, align: 'right', sort: 'true'}
                , {field: 'PAY_DATE', event: 'setSign', title: '应收租日', width: 120, sort: 'true'}
                , {field: 'INFO', event: 'setSign', title: '备注', width: 120, sort: 'true'}
                /* , {field: 'PRICE_TYPE', event: 'setSign', title: '账单状态', align: 'center',width: 120}*/
                , {field: 'NAME', event: 'setSign', title: '操作人', width: 120, sort: 'true'}
                , {field: 'CREATE_DATE', event: 'setSign', title: '操作时间', width: 170, sort: 'true'}
                , {fixed: 'right', width: 160, align: 'center', title: '操作', toolbar: '#ziyongbar'}

            ]]
            , id: 'ZIYONG'
            , page: true
            , height: 'auto'
            , limit: '10'
            , size: 'sm' //小尺寸的表格
        });
        //操作详情
        var data = {};
        data.roomid = roomid;
        table.render({
            elem: '#xiangqing'
            , url: '/recordController/listroom'
            , where: data
            , cols: [[
                {field: 'DETAILS', event: 'setSign', title: '操作详情', width: 200}
                , {field: 'OPERATOR', event: 'setSign', title: '操作人', width: 150}
                , {field: 'OPERA_TIME', event: 'setSign', title: '操作时间', width: 150}

            ]]
            , id: ''
            , page: true
            , height: 'auto'
            , limit: '10'
            , size: 'sm' //小尺寸的表格
        });
    });
    //已处理账单 监听工具条
    table.on('tool(yichulif)', function (obj) {
        var data = obj.data //获得当前行数据
            , layEvent = obj.event; //获得 lay-event 对应的值
        var nametype = data.BILL_NAME;
        if (layEvent === 'detail') {
            parent.layer.open({
                zIndex: 1000,
                type: 2,    //弹出类型
                title: '查看账单',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['80%', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/bill_check.html?type=' + escape(nametype) + '&BILL_ID=' + data.ID + ''  //iframe的url
            });
        } else if (layEvent === 'edit') {
            layer.confirm('确定收费？', function (index) {
                layer.close(index);
                //向服务端发送删除指令
            });
        }
    });
    //待处理账单 监听工具条
    table.on('tool(dclf)', function (obj) {
        var data = obj.data //获得当前行数据
            , layEvent = obj.event; //获得 lay-event 对应的值
        var ROOM_NUM = data.ROOM_NUM;
        var nametype = data.BILL_NAME;
        if (layEvent === 'detail') {
            parent.layer.open({
                zIndex: 1000,
                type: 2,    //弹出类型
                title: '查看账单',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['80%', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/bill_check.html?type=' + escape(nametype) + '&BILL_ID=' + data.ID + ''  //iframe的url
            });
        } else if (layEvent === 'dclsf') {
            parent.layer.open({
                zIndex: 1000,
                type: 2,    //弹出类型
                title: '收费',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['80%', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/charge.html?&roomnum=' + escape(ROOM_NUM) + '&type=' + escape(nametype) + '&BILL_ID=' + data.ID + ''  //iframe的url
            });
            $(this).blur(); //移除焦点，防止点击回车按钮造成多次打开
        }
    });
    //weilai账单 监听工具条
    table.on('tool(wlf)', function (obj) {
        var data = obj.data //获得当前行数据
            , layEvent = obj.event; //获得 lay-event 对应的值
        var ROOM_NUM = data.ROOM_NUM;
        var nametype = data.BILL_NAME;
        if (layEvent === 'detail') {
            parent.layer.open({
                zIndex: 1000,
                type: 2,    //弹出类型
                title: '查看账单',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['80%', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/bill_check.html?type=' + escape(nametype) + '&BILL_ID=' + data.ID + ''  //iframe的url
            });
        } else if (layEvent === 'edit') {
            parent.layer.open({
                zIndex: 1000,
                type: 2,    //弹出类型
                title: '收费',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['80%', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/charge.html?&roomnum=' + escape(ROOM_NUM) + '&type=' + escape(nametype) + '&BILL_ID=' + data.ID + ''  //iframe的url
            });
            $(this).blur(); //移除焦点，防止点击回车按钮造成多次打开
        }
    });
    //自用账单    查看
    table.on('tool(ziyongf)', function (obj) {
        var data = obj.data //获得当前行数据
            , layEvent = obj.event; //获得 lay-event 对应的值
        var nametype = data.BILL_NAME;
        var type;
        //自用账单标识问题 为了查看不显示 实际收款
        var hideShoukuan = "1";
        if (layEvent === 'detail') {
            parent.layer.open({
                zIndex: 1000,
                type: 2,    //弹出类型
                title: '查看账单',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['80%', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/bill_check.html?&hd=' + escape(hideShoukuan) + '&&type=' + escape(nametype) + '&BILL_ID=' + data.ID + ''  //iframe的url
            });
        } else if (layEvent === 'xiugai') {
            parent.layer.open({
                zIndex: 1000,
                type: 2,    //弹出类型
                title: '查看账单',   //标题
                closeBtn: 1,    //显示关闭按钮
                shade: [0.3],   //遮罩透明度
                area: ['80%', '90%'],  //打开窗口的宽高
                time: 0,    //几秒后自动关闭，默认0时不关闭
                anim: 1,    //动画效果
                resize: false,  //设置成不允许拉伸
                content: '../../../webhtml/contract/bill_check.html?&type=' + escape(nametype) + '&button=edit&BILL_ID=' + data.ID + ''  //iframe的url
            });

        }
    });
    //合同退租操作
    $(".tuizu").click(function () {
        parent.layer.open({
            zIndex: 1000,
            type: 2,    //弹出类型
            title: '合同退租',   //标题
            closeBtn: 1,    //显示关闭按钮
            shade: [0.3],   //遮罩透明度
            area: ['80%', '90%'],  //打开窗口的宽高
            time: 0,    //几秒后自动关闭，默认0时不关闭
            anim: 1,    //动画效果
            resize: false,  //设置成不允许拉伸
            content: '../../../webhtml/contract/surrender_of_tenancy.html?CONTRACT_ID=' + contractID + ''  //iframe的url
        });
    });
    //合同查看操作
    $(".chakan").click(function () {
        parent.layer.open({
            zIndex: 1000,
            type: 2,    //弹出类型
            title: '查看合同',   //标题
            closeBtn: 1,    //显示关闭按钮
            shade: [0.3],   //遮罩透明度
            area: ['80%', '90%'],  //打开窗口的宽高
            time: 0,    //几秒后自动关闭，默认0时不关闭
            anim: 1,    //动画效果
            resize: false,  //设置成不允许拉伸
            content: '../../../webhtml/contract/contract_info.html?CONTRACT_ID=' + contractID + ''  //iframe的url
        });
    });
    //历史合同查看操作
    $(".History_view").click(function () {
        var HistoryContractID = $(this).find($(".hiddenCon")).val();
        parent.layer.open({
            zIndex: 1000,
            type: 2,    //弹出类型
            title: '查看合同',   //标题
            closeBtn: 1,    //显示关闭按钮
            shade: [0.3],   //遮罩透明度
            area: ['80%', '90%'],  //打开窗口的宽高
            time: 0,    //几秒后自动关闭，默认0时不关闭
            anim: 1,    //动画效果
            resize: false,  //设置成不允许拉伸
            content: '../../../webhtml/contract/contract_info.html?CONTRACT_ID=' + HistoryContractID + ''  //iframe的url
        });
    });


});


